/*
File: dbmsTest.cpp
Authors: Team 3- Sam Stewart, Dylan McDougall, Stephen Ten Eyck
Date: 06/05/12
CSCE 315- 100 Summer 1 2012
*/

/*
This is the program that tests the DBMS capabilities.
*/

//includes
#include "table.h"
#include "dbms.h"
#include "parser.h"

int main(){
	//create engine
	DBMS db;
	vector<string> tokens;
	Parser p;
	ifstream testFile;
	char cStr[500];
    string str = "";
	
	//test input file
	testFile.open("test.txt");
	if(!testFile.is_open()){
		error("Can't open file\n");
	}
	while(testFile.good()){
		testFile.getline(cStr,500);
		if((int)cStr[0] != 13 && (int)cStr[0] != 0){
			str = string(cStr);
			p.setString(str);
			cout << "\ninput: " << str << endl;
			p.parse();
			str = "";
			tokens = p.getTokens();
			db.execute(tokens);
			cout << "\n\n=====================================\n\n";
		}
	}
	
	//test read
	cout << "Testing read\n";
	db.read("ATest.db");
	db.show(db.getTable("ATest"));
	
	//shell testing
	cout << "Testing database engine.\n Type \"QUIT\" to quit\n";
	while(str != "QUIT"){
		cout << '>';
		getline(cin, str);
		if(str != "QUIT"){
			p.setString(str);
			p.parse();
			str = "";
			tokens = p.getTokens();
			db.execute(tokens);
			cout << "\n\n=====================================\n\n";
		}
	}
}
